package com.hh.front.controller;

import com.hh.common.page.CommonPage;
import com.hh.common.request.PageParamRequest;
import com.hh.common.request.UserExtractRequest;
import com.hh.common.response.CommonResult;
import com.hh.common.response.commission.BrokerageRecordResponse;
import com.hh.common.response.commission.UserCommissionInfoResponse;
import com.hh.common.response.commission.WithdrawalRecordResponse;
import com.hh.front.service.UserCenterService;
import com.hh.service.service.UserBrokerageRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户佣金
 */
@RestController()
@RequestMapping("api/front/commission")
public class UserCommissionController {

    @Autowired
    private UserBrokerageRecordService userBrokerageRecordService;

    @Autowired
    private UserCenterService userCenterService;

    /**
     *用户佣金信息
     * @return
     */
    @RequestMapping(value = "/getCommissionInfo", method = RequestMethod.GET)
    public CommonResult<UserCommissionInfoResponse> getCommissionInfo(){
        return CommonResult.success(userBrokerageRecordService.getCommissionInfo());
    }

    /**
     * 提现申请
     */
    @ApiOperation(value = "提现申请")
    @RequestMapping(value = "/withdrawalApply", method = RequestMethod.POST)
    public CommonResult<Boolean> withdrawalApply(@RequestBody @Validated UserExtractRequest request) {
        return CommonResult.success(userCenterService.extractCash(request));
    }

    /**
     * 提现记录
     */
    @ApiOperation(value = "提现记录")
    @RequestMapping(value = "/withdrawalRecord", method = RequestMethod.GET)
    public CommonResult<CommonPage<WithdrawalRecordResponse>> getExtractRecord(@Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(userBrokerageRecordService.withdrawalRecord(pageParamRequest)));
    }

    /**
     * 推广佣金明细
     * @param pageParamRequest
     * @return
     */
    @RequestMapping(value = "/promotionList", method = RequestMethod.GET)
    public CommonResult<CommonPage<BrokerageRecordResponse>> promotionList(@Validated PageParamRequest pageParamRequest){
        return CommonResult.success(CommonPage.restPage(userBrokerageRecordService.promotionList(pageParamRequest)));
    }
}
